﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Script.Serialization;
using Models;
using Newtonsoft.Json.Linq;

namespace ASP.NET_MVC_WebAPI_Demo.Controllers
{
    public class DefaultController : ApiController
    {
        // GET api/<controller>   推荐接口工具Apifox【https://apifox.com】
        public HttpResponseMessage Get()
        {
            //return new string[] { "value1", "value2" };
            List<User> list = new List<User>();
            list.Add(new User("小明", 20, "男"));
            list.Add(new User("小王", 21, "男"));
            list.Add(new User("小红", 22, "女"));
            list.Add(new User("小芳", 19, "女"));
            list.Add(new User("小李", 18, "男"));
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var res = Request.CreateResponse(HttpStatusCode.OK);
            var jsonmsgs = JsonConvert.SerializeObject(list);
            res.Content = new StringContent(jsonmsgs, System.Text.Encoding.UTF8, "application/json");
            return res;
        }

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<controller>

        public string Post([FromBody] User value)
        {
            return "ok";
        }

        // PUT api/<controller>/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }
    }
}
